package com.example.pcbackend.globa;

import com.example.pcbackend.enums.ResultCode;
import lombok.Data;

/**
 * @Description: 全局异常类
 * @Author: wesley
 * @Date: 2021/4/15 11:42
 */
@Data
public class GlobalException extends RuntimeException{

    /**
     * 错误枚举
     */
    private ResultCode resultCode;

    /**
     * 默认 500错误
     */
    public GlobalException() {
        resultCode = ResultCode.SERVER_ERROR;
    }

    /**
     * 默认 500错误，并且自定义 message
     * @param message
     */
    public GlobalException(String message) {
        resultCode = ResultCode.SERVER_ERROR;
        resultCode.setMsg(message);
    }

    /**
     *
     * @param resultCode 错误枚举
     */
    public GlobalException(ResultCode resultCode) {
        this.resultCode = resultCode;
    }

    /**
     * 覆盖 message 描述信息
     * @param message 消息
     * @param resultCode 错误枚举
     */
    public GlobalException(ResultCode resultCode, String message) {
        super(message);
        this.resultCode = resultCode;
        this.resultCode.setMsg(message);
    }
}
